"""
转化“故障描述”部分
@Time: 2021/2/18 15:12
@Author:
@File: fault_desc.py
"""
from rdflib import URIRef, Literal, XSD
from pyfuseki.term import RDFList

from mapper.owl_mapper import RdfPrefix as rp, ObjectProperty as op, DataProperty as dp
from models.dto.mark_dto.fault_card_mark_dto.sections import FaultDescriptionMark



def convert_fault_desc(fault_desc: FaultDescriptionMark, fault_desc_uri: URIRef) -> RDFList:
    """
    将故障描述部分转化为 RDF 数据
    :param fault_desc: 故障描述的信息
    :param fault_desc_uri: 该故障描述实体对应的uri
    :return:
    """
    equipment_uri = rp.Equipment.uid()  # 设备的uri，使用 uuid1 生成唯一 id
    phenomenon_uri = rp.Phenomenon.uid() # 故障现象的uri
    equip_func_uri = rp.EquipmentFunction.uid()  # 设备功能的uri
    rdf_list = [
        (fault_desc_uri, op.hasFacultyEquipment.value, equipment_uri),  # 有故障设备
        (equipment_uri, dp.hasName.value, Literal(fault_desc.equipment, datatype=XSD.string)),  # 设备名
        (equipment_uri, op.hasFunction.value, equip_func_uri),  # 设备有设备功能
        (equip_func_uri, dp.hasName.value, Literal(fault_desc.equipment_func, datatype=XSD.string)),  # 设备功能名
        (fault_desc_uri, op.hasPhenomenon.value, phenomenon_uri),  # 有故障现象
        (phenomenon_uri, dp.hasExpression.value, Literal(fault_desc.phenomenon, datatype=XSD.string))  # 现象的表述
    ]
    return rdf_list


